import { localUrl } from '@renderer/utils'

export function videoPage({ page = 1, pageSize = 1, name = '' }) {
  return window.electron.ipcRenderer.invoke('video/page', { page, pageSize, name })
}

export function findVideo(id, is_common) {
  return window.electron.ipcRenderer.invoke('video/find', id, is_common)
}

export function removeVideo(id) {
  return window.electron.ipcRenderer.invoke('video/remove', id)
}

export function saveVideo(video) {
  // id, model_id, name, text_content, voice_id, audio_path
  return window.electron.ipcRenderer.invoke('video/save', video)
}

export function makeVideo(id) {
  return window.electron.ipcRenderer.invoke('video/make', id)
}

export function makeVideoCommon(id) {
  return window.electron.ipcRenderer.invoke('video/make_common', id)
}

export function exportVideo(id, outputPath, is_caption) {
  return window.electron.ipcRenderer.invoke('video/export', id, outputPath, is_caption)
}

export function modifyVideo(video) {
  return window.electron.ipcRenderer.invoke('video/modify', video)
}

export function captionVideo(videoId, file_path, caption_path, output_path) {
  return window.electron.ipcRenderer.invoke('video/caption', videoId, file_path, caption_path, output_path)
}

export function printedVideo(printedVideo) {
  return window.electron.ipcRenderer.invoke('video/printed', printedVideo)
}

export function countVideo(name = '') {
  return window.electron.ipcRenderer.invoke('video/count', name)
}

export function modelPage({ page = 1, pageSize = 1, name = '' }) {
  return window.electron.ipcRenderer.invoke('model/page', { page, pageSize, name })
}

export function findModel(id) {
  return window.electron.ipcRenderer.invoke('model/find', id)
}

export function findModelCommon(id) {
  return window.electron.ipcRenderer.invoke('model/find_common', id)
}

export function addModel({ name, videoPath, synced, primaryCategoryId, secondaryCategoryId, tertiaryCategoryId, lang}) {
  videoPath = localUrl.delFileProtocol(videoPath)
  return window.electron.ipcRenderer.invoke('model/addModel', name, videoPath, synced, primaryCategoryId, secondaryCategoryId, tertiaryCategoryId, lang)
}

export function updateDigitalHuman(modelData) {
  return window.electron.ipcRenderer.invoke('model/updateModel', modelData)
}

export function deleteDigitalHuman(modelId) {
  return window.electron.ipcRenderer.invoke('model/deleteModel', modelId)
}

export function countModel(name = '') {
  return window.electron.ipcRenderer.invoke('model/count', name)
}

export function countCommonModel(name = '') {
  return window.electron.ipcRenderer.invoke('model/count_common', name)
}

export function removeModel(id) {
  return window.electron.ipcRenderer.invoke('model/remove', id)
}

export function getContext(key) {
  return window.electron.ipcRenderer.invoke('context/get', key)
}

export function saveContext(key, val) {
  return window.electron.ipcRenderer.invoke('context/save', key, val)
}

export function audition(voiceId, is_common, text) {
  return window.electron.ipcRenderer.invoke('voice/audition', voiceId, is_common, text)
}

// 获取分类树
export function getCategoryTree() {
  return window.electron.ipcRenderer.invoke('category/getTree');
}

// 获取子分类
export function getSubCategories(parentId) {
  return window.electron.ipcRenderer.invoke('category/getSubCategories', parentId);
}

// 添加分类
export function addCategory(name, parentId, level) {
  return window.electron.ipcRenderer.invoke('category/add', name, parentId, level);
}

// 删除分类
export function deleteCategory(categoryId) {
  return window.electron.ipcRenderer.invoke('category/delete', categoryId);
}

// 获取公共模特列表
export function getCommonModelList(params) {
  return window.electron.ipcRenderer.invoke('model/list', params);
}

// 获取公共模特列表2
export function getCommonModelList2(params) {
  return window.electron.ipcRenderer.invoke('model/list2', params);
}

// 获取服务器ip
export function getIP() {
  return window.electron.ipcRenderer.invoke('serverConfig/getIP');
}
